'use strict';

var APP = angular.module('zhugefang', [
        // 'ngAnimate',
        // 'ngResource',
        // 'ngRoute',
        // 'ngSanitize',
        // 'ngTouch',
        // 'ngMessages'
        'ui.router',
        'zg-directive'
    ])
    .config(function($stateProvider,$urlRouterProvider){
        $urlRouterProvider.when("","/list");
        $stateProvider.state('list',{
            url:'/list',
            templateUrl:'view/list.html',
            controller:'listCtr as listCtr'
        })
        .state('detailsCtrl',{
            url:'/details/:house_id',
            templateUrl:'view/details.html',
            controller:'detailsCtrl as detailsCtrl'
        })
    })

    .controller('detailsCtrl',function($rootScope,$scope,$http,$stateParams,$state){
        console.log($stateParams.house_id);
        $rootScope.map = [116.404, 39.915];
        // var url = 'http://test.zhugefang.com/API/House/houseinfo',
        //     data = {
        //         house_id: $stateParams.house_id
        //     },
        //     transFn = function(data) {
        //         return $.param(data);
        //     },
        //     postCfg = {
        //         headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
        //         transformRequest: transFn
        //     };
        // $http.post(url, data, postCfg)

        
        $http({
            url:"http://test.zhugefang.com/API/House/houseinfo"+"?house_id="+$stateParams.house_id,
            method:"POST",
            dataType:"json",
            })
        .success(function(data) {
            console.log(data); 
        　　$scope.o = data ;
            $scope.match = {
                "data": {
                    "price": {
                        "weight": 30,
                        "term": "30%"
                    },
                    "huxing": {
                        "weight": 40,
                        "term": "40%"
                    },
                    "district": {
                        "weight": 20,
                        "term": "20%"
                    },
                    "appreciation": {
                        "weight": 10,
                        "term": "10%"
                    }
                },
                "total_match": "85%"
            };
            $scope.dd = "test";
            Zepto(".ui-loading-block").removeClass("show");
        }).error(function(){
            console.log('error')
        });
    })
    .controller('listCtr',function($scope,$http){
        $http.get("http://test.zhugefang.com/API/House/gethouseList").success(function(data) {
            // console.log(data); 
        　　$scope.o = data ;
            Zepto(".ui-loading-block").removeClass("show");
        }).error(function(){
            console.log('error')
        });

    })

 
